//
//  SwipableViewController.m
//  oschina_song
//
//  Created by song on 16/1/25.
//  Copyright © 2016年 song. All rights reserved.
//

#import "SwipableViewController.h"

@implementation SwipableViewController

-(id)initWithTitle:(NSString *)title addSubTitles:(NSArray *)subTitles andControllers:(NSArray *)controllers
{
    self =  [super init];
    if(self)
    {
        [self.view setBackgroundColor:[UIColor whiteColor]];
        // 让导航也占一定的位置
        self.edgesForExtendedLayout = UIRectEdgeNone;
        CGFloat titlebarHeight  = 36;
        TitleBarView *titlebar = [[TitleBarView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width,titlebarHeight) andTitles:subTitles];
        titlebar.backgroundColor = [UIColor clearColor];
        _titleBar  = titlebar;
        [self.view addSubview:titlebar];
        
        _viewPager  = [[HorizonalTableViewController alloc ] initWithViewControllers:controllers];
        CGFloat height = self.view.bounds.size.height  ;
        _viewPager.view.frame  = CGRectMake(0, titlebarHeight, self.view.bounds.size.width, self.view.bounds.size.height+200);
        [self addChildViewController:self.viewPager];
        [self.view addSubview:_viewPager.view];
        
        __weak TitleBarView *weakTitleBar = _titleBar;
        __weak HorizonalTableViewController *weakViewPage =_viewPager;
        
        _titleBar.titleButtonCLicked =^(NSUInteger index)
        {
            [weakViewPage scrollToViewAtIndex:index];
        };
        
    }
    
    
    return self;
}

@end
